use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone)]
pub struct Response<S>{
    code: u32,
    message: Option<String>,
    data: Option<S>,
}

impl <S> Response<S> {
    pub fn ok() -> Response<S> {
        Response{
            code: 0,
            message: None,
            data: None,
        }
    }

    pub fn error(code: u32) -> Response<S>{
        Response{
            code,
            message: None,
            data: None,
        }
    }

    pub fn message(&mut self, message: String)  -> &mut Response<S> {
        self.message = Some(message);
        self
    }

    pub fn data(&mut self, data: S)  -> &mut Response<S> {
        self.data = Some(data);
        self
    }

    pub fn get_code(&self) -> u32{
        self.code
    }
}